package com.ibm.mall.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ibm.mall.base.BaseAction;
import com.ibm.mall.model.CommodityClass;
import com.ibm.mall.model.OrderForm;
import com.ibm.mall.model.PageBean;
import com.ibm.mall.util.QueryHelper;
import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class OrderAction extends BaseAction<OrderForm> {

	private static final long serialVersionUID = 1L;
	
	private Map responseJson;
	
	public String list() {
		return "list";
	}
	
	public String getData(){
        Map<String, Object> map = new HashMap<String, Object>();
        QueryHelper queryHelper=null;
        if(model.getOrderFormNo()!=null&&!model.getOrderFormNo().equals("")){
        	queryHelper=new QueryHelper(OrderForm.class, "o")//
			.addCondition("o.status=?", (short)0)//查询出未被删除的
			.addCondition("o.orderFormNo=?", model.getOrderFormNo())
			.addOrderProperty("o.id", true);
        }else{
        	queryHelper=new QueryHelper(OrderForm.class, "o")//
			.addCondition("o.status=?", (short)0)//查询出未被删除的
			.addOrderProperty("o.id", true);
        }
        //分页查询获得pageBean
        PageBean pageBean=orderFormService.getPageBean(page,rows,queryHelper);
        map.put("rows", pageBean.getRecordList());
        map.put("total", pageBean.getRecordCount());
        this.setResponseJson(map);
        return "getData";
    }
	
	public String delete() {
		OrderForm orderForm=orderFormService.getOrderFormById(model.getId());
		orderForm.setStatus((short)1);
		orderFormService.updateOrderForm(orderForm);
		return "delete";
	}
	
	public String deliver() {
		OrderForm orderForm=orderFormService.getOrderFormById(model.getId());
		orderForm.setOrderFormStatus((short) 2);
		orderFormService.updateOrderForm(orderForm);
		return "deliver";
	}

	public Map getResponseJson() {   
        return responseJson;   
    }
    
    public void setResponseJson(Map responseJson) {   
        this.responseJson = responseJson;   
    }

}
